<template>
    <div class="file-avatar">
        <icon class="icon" type="ios-add"/>
        <img :src="$root.FILE_PATH + value" alt="">
        <input type="file" @change="handlerFile">
    </div>
</template>

<script>

    export default {
        name: "avatar-file",
        props: {
            value: String
        },
        data() {
            return {}
        },
        methods: {
            async handlerFile(e) {
                const file = e.target.files[0]
                let formData = new FormData()
                formData.append('file', file)
                try {
                    let {data} = await this.$http.post(this.$API.FILE, formData)
                    this.$emit('input',data.url)
                    e.target.value = ''
                } catch (e) {
                    console.log(e)
                }
            }
        }
    }
</script>
